package 链表模拟实现;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

class Student{
    private int age;

    public Student(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "链表模拟实现.Student{" +
                "age=" + age +
                '}';
    }
}
public class LinkedTest {
    public static void main(String[] args) {
        LinkedList<Student> list=new LinkedList();
        Student student=new Student(66);
        list.add(new Student(12));
        list.add(1,student);
        System.out.println(list.indexOf(student));
        System.out.println(list.get(0));
        list.set(1,new Student(12));
        System.out.println(list);
    }
    public static void main1(String[] args) {
        LinkedList<Integer>list=new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        LinkedList<Integer>list2=new LinkedList<>();
        list2.add(1);
        list2.add(2);
        list2.add(3);
        Iterator it=list.listIterator();
        while (it.hasNext()){
            System.out.print(it.next()+" ");
        }
        System.out.println();

        ListIterator it2=list2.listIterator(list2.size());
        while (it2.hasPrevious()){
            System.out.print(it2.previous()+" ");
        }
        System.out.println();
    }
}
